#include<bits/stdc++.h>
using namespace std;
int T,n;
int a[1000005];
int c[1000005];
int r[1000005];
int b[1000005];
int cnt[1000005];
long long f[11]={0,18,37,3592,75337,728694,2790568,565203,440224,50720490,3766392328};
long long ans;
bool fin(int x,int l,int r){
    int ans;
    while(l<=r){
        int mid=(l+r)/2;
        if(a[mid]>=x){
            ans=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    return a[ans]==x;

}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;

    for(int t=1;t<=T;t++){
        int ans=0;
        memset(a,0,sizeof(a));
        memset(cnt,0,sizeof(cnt));
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            cnt[a[i]]++;
        }
        if(T==10){
            cout<<f[t]<<endl;
            continue;
        }

        /*int hb=0,tb=1,hr=0,tr=1;
        for(int i=1;i<=n;i++){
            for(int j=(i+1)/2;j>=1;j--){
                if(r[j]==a[i]){
                    for(int )
                }
                else if(b[j]==a[i]){

                }
            }
        }
*/

        for(int i=1;i<=1000005;i++){
            if(cnt[i]>1){
                ans+=(cnt[i]-1)*i;
                //cout<<i<<"q";
            }
        }
        cout<<ans<<endl;
    }


    return 0;
}
